import akka.actor.{Actor, ActorLogging, Props}
import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope
import akka.routing.FromConfig

/**
  * Created by dl 
  */
class Master extends Actor with ActorLogging{
  //下述FromConf.xxx从配置文件中读取部署配置，本Master actor我们以单例模式创建，其路径为/user/masterManager/singleton，因此部署的配置键为"/masterManager/singleton/workerRouter"（配置键需省掉/user）
  private val router = context.actorOf(FromConfig.props(Props[WorkerActor]), name = "workerRouter")

  override def receive: Receive = {
    case x =>
      log.info(s"got message on master, msg: $x, actor me: ${self.path}")
      router forward ConsistentHashableEnvelope(x, x) //转发给路由器，路由器将选择一个worker让其接收消息
  }
}
